package com.starinside.wp.controller;


import com.starinside.wp.components.MemVerificationCache;
import com.starinside.wp.domain.WxUser;
import com.starinside.wp.foundation.model.ErrorCode;
import com.starinside.wp.foundation.model.StatusResponse;
import com.starinside.wp.service.UserActiveRegistrationService;
import com.tuo51.foudation.utils.export.HealthReportUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

import static com.starinside.wp.foundation.constant.RequestConstant.TICKET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;


/**
 * (UserActiveRegistration)表控制层
 *
 * @author makejava
 * @since 2025-02-21 15:11:02
 */
@RestController
@RequestMapping("userActiveRegistration")
public class UserActiveRegistrationController {

    @Autowired
    UserActiveRegistrationService userActiveRegistrationService;
    @Autowired
    protected MemVerificationCache cache;


    /**
     * 报名
     */
    @PostMapping
    @RequestMapping(value = "/application", method = POST)
    public StatusResponse  application(HttpServletRequest req,String childId, String activeId,String parentId,String parentMobile,String relation,String name){
        WxUser user = (WxUser) req.getSession().getAttribute("loginUser");
//        if(StringUtils.isEmpty(user.getParentId()) || StringUtils.isEmpty(user.getDefaultBabyId()) || StringUtils.isEmpty(user.getParentMobile())){
//            return StatusResponse.error(ErrorCode.CHILDREN_NOT_EXIST,"当前账号下没有宝宝信息");
//        }
        userActiveRegistrationService.application(activeId,childId,parentId,parentMobile,relation,name);
        return StatusResponse.success();
    }

    /**
     * 取消报名
     */
    @PostMapping
    @RequestMapping(value = "/calApplication", method = POST)
    public StatusResponse  calApplication(HttpServletRequest req,String childId, String activeId){
        WxUser user = (WxUser) req.getSession().getAttribute("loginUser");
//        if(StringUtils.isEmpty(user.getParentId()) || StringUtils.isEmpty(user.getDefaultBabyId()) || StringUtils.isEmpty(user.getParentMobile())){
//            return StatusResponse.error(ErrorCode.CHILDREN_NOT_EXIST,"当前账号下没有宝宝信息");
//        }
        userActiveRegistrationService.calApplication(activeId,childId);
        return StatusResponse.success();
    }
}

